<template>
  <div class="StudentQueryRes">
    <el-breadcrumb separator="/" class="breadcrumb-bottom">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>毕业设计</el-breadcrumb-item>
      <el-breadcrumb-item>学生查看分配结果</el-breadcrumb-item>
    </el-breadcrumb>
    <el-table
      :data="studentQueryTable"
      style="width: 100%"
    >
      <el-table-column
        prop="graduateTitle"
        label="课题名称"
        min-width="120"
        sortable>
      </el-table-column>
      <el-table-column
        prop="titleSource"
        label="课题来源"
        min-width="120"
        sortable>
      </el-table-column>
      <el-table-column
        prop="teacherName"
        label="负责教师"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="teacherTel"
        label="联系电话"
        min-width="120">
      </el-table-column>
      <el-table-column
        label="要求人数"
        min-width="120">
        <template scope="scope">
          <el-button
            @click="checkResults(scope.row.graduateProgramID)"
            type="text">
            {{scope.row.number}}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        prop="itemCategoryName"
        label="项目类别名称"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="itemCategoryID"
        label="项目类别编号"
        min-width="120">
      </el-table-column>
      <el-table-column
        label="课题附件"
        min-width="120">
        <template scope="scope">
          <el-button
            @click.native.prevent="showAttachment(scope.row.titleAttachment)"
            type="text">
            {{scope.row.titleAttachmentName}}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        min-width="120">
        <template scope="scope">
          <el-button
            @click="toCommitGraduation(scope.row.graduateProgramID)"
            type="text">
            提交毕设成果
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="学生信息" v-model="dialogTableVisible">
      <el-table :data="studentData">
        <el-table-column property="studentName" label="学生姓名" width="150"></el-table-column>
        <el-table-column property="studentID" label="学号" width="200"></el-table-column>
        <el-table-column property="className" label="班级"></el-table-column>
        <el-table-column property="phone" label="联系方式"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
  export default{
    name: "StudentQueryRes",
    data(){
      return {
        studentQueryTable: [
          {
            graduateProgramID: '',
            graduateTitle: '',
            titleSource: '',
            itemCategoryID: '',
            itemCategoryName: '',
            number: '',
            teacherName: '',
            teacherTel: '',
            titleAttachment: '',
            titleAttachmentName: ''
          }
        ],
        studentData: [{
          studentName: '',
          studentID: '',
          className: '',
          phone: ''
        }],
        dialogTableVisible: false,
        studentID: '201320010101',
        apiUrl: this.$until.url + '/graduateProgram/getGraduateInfoStudent',
        checkUrl: this.$until.url + '/graduateProgram/getStudentInfo',
      }
    },
    mounted: function () {
      this.$nextTick(function () {
        this.init();
      });
    },
    methods: {
      init(){
        this.res();
      },
      res(){
        this.$http.get(this.apiUrl, {
            params: {
              studentID: this.studentID
            }
          }
        ).then((res) => {
          this.studentQueryTable = res.body
        }, (err) => {
          console.log(err);
        })
      },
      showAttachment(titleAttachment){
        window.open(this.$until.url + '/' + titleAttachment)
      },
      checkResults(graduateProgramID){
        this.$http.get(this.checkUrl, {
            params: {
              graduateProgramID: graduateProgramID,
            }
          }
        ).then((res) => {
          this.studentData = res.body;
          this.dialogTableVisible = true
        }, (err) => {
          console.log(err);
        })
      },
      toCommitGraduation(graduateProgramID){
        this.$router.push({
          path: 'commitGraduation',
          query: {
            studentID: this.studentID,
            graduateProgramID: graduateProgramID,
          }
        })
      }
    }
  }
</script>
